<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Animal {
            constructor(sex, ability) {
                this.sex = sex;
                this.ability = ability;
            }
            saySex() {
                console.log(this.sex);
            }
        }
        Object.assign(Animal.prototype, {
            sayAbility() {
                console.log(this.ability);
            }
        })
        class Dog extends Animal {
            /* 类继承之后,构造函数第一行必须写super关键字 去继承父类的属性*/
            constructor(sex, ability, food, wifeNum) {
                super(sex, ability),
                    this.food = food,
                    this.wifeNum = wifeNum
            }
            // 写不写都已经继承
            /* 在子类的方法中调用父类的方法 可以通过this或super去调用 */
            // show(){
            //     super.saySex();
            // }
        }
        var dog = new Dog("gong", "eat", "shi", 6)
        console.log(dog);
        dog.saySex();
    </script>
</body>

</html>